package sample.web.config;

import com.amazonaws.ClientConfiguration;
import com.amazonaws.Protocol;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;

public class S3Config {
    
    //测试环境
    public final static String ENDPOINT = "http://10.170.24.211:8060";
    public final static String accessKey = "K5O8Z1Q30V0PFMEUSA9D";
    public final static String secretKey = "26BXF7DhIvCAnKocZo0BA5lGcdvE80RHVY5KpMbN";
    public final static String bucket_name = "tddtests3";

    public static AmazonS3 getAmazonS3() {
        AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);

        ClientConfiguration clientConfig = new ClientConfiguration();

        clientConfig.setProtocol(Protocol.HTTP);

        AmazonS3ClientBuilder builder = AmazonS3ClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(credentials));
        AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration(ENDPOINT, Regions.AP_SOUTHEAST_1.getName());
        builder.setEndpointConfiguration(endpointConfiguration);

        return builder.build();
    }
}